﻿using DevExpress.XtraTab;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLTTAN.UserControls;

using QLTTAN.Form;
namespace QLTTAN
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {

        string username = "";

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            frmDangNhap frmDN = new frmDangNhap();
            frmDN.ShowDialog();

            username = frmDN.username;
            txtPhanQuyen.Caption = "Bạn đang đăng nhập với tên tài khoản " + username + " quyền " + frmDN.phanquyen;
            SetEnableControls(frmDN.MaQuyen);
        }

        private void SetEnableControls(int maquyen)
        {
            switch(maquyen)
            {
                case 1: // admin và quản lí
                case 2:
                    ribbonPageGroupCSDL.Enabled = true;
                    ribbonPageGroupNguoiDung.Enabled = true;
                    btnDSTaiKhoan.Enabled = true;
                    ribbonPageGroupQuyDinh.Enabled = true;
                    ribbonPageGroupGiaoVu.Enabled = true;
                    ribbonPageGroupKeToan.Enabled = true;
                    ribbonPageGroupTraCuu.Enabled = true;
                    btnBaoCaoHocVu.Enabled = true;
                    btnBaoCaoGhiDanh.Enabled = true;
                    btnBaoCaoKeToan.Enabled = true;
                    break;
                case 3: // ghi danh
                    ribbonPageGroupCSDL.Enabled = false;
                    btnDSTaiKhoan.Enabled = false;
                    ribbonPageGroupQuyDinh.Enabled = false;
                    ribbonPageGroupGiaoVu.Enabled = false;
                    ribbonPageGroupKeToan.Enabled = false;
                    btnBaoCaoHocVu.Enabled = false;
                    btnBaoCaoKeToan.Enabled = false;
                    break;
                case 4: // học vụ
                    ribbonPageGroupCSDL.Enabled = false;
                    btnDSTaiKhoan.Enabled = false;
                    ribbonPageGroupQuyDinh.Enabled = false;
                    ribbonPageGroupKeToan.Enabled = false;
                    btnBaoCaoGhiDanh.Enabled = false;
                    btnBaoCaoKeToan.Enabled = false;
                    break;
                case 5: // kế toán
                    ribbonPageGroupCSDL.Enabled = false;
                    btnDSTaiKhoan.Enabled = false;
                    ribbonPageGroupQuyDinh.Enabled = false;
                    ribbonPageGroupGhiDanh.Enabled = false;
                    ribbonPageGroupGiaoVu.Enabled = false;
                    btnBaoCaoGhiDanh.Enabled = false;
                    btnBaoCaoHocVu.Enabled = false;
                    break;
            }
        }

        #region HỆ THỐNG

        private void btnBackupCSDL_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnRestoreCSDL_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnDangXuat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmDangNhap frmDN = new frmDangNhap();
            frmDN.ShowDialog();

            username = frmDN.username;
            txtPhanQuyen.Caption = "Bạn đang đăng nhập với tên tài khoản " + username + " quyền " + frmDN.phanquyen;
            SetEnableControls(frmDN.MaQuyen);
        }

        private void btnDSTaiKhoan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmDanhSachTaiKhoan frmDSTK = new frmDanhSachTaiKhoan();
            frmDSTK.ShowDialog();
        }

        private void btnDoiMatKhau_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmTaiKhoan frmTK = new frmTaiKhoan();
            frmTK.username = username;
            frmTK.ShowDialog();
        }

        private void btnThayDoiQD_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmThayDoiQuyDinh frmTDQD = new frmThayDoiQuyDinh();
            frmTDQD.ShowDialog();
        }

        #endregion

        #region QUẢN LÍ

        private void btnThemHocVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmHocVien frmHV = new frmHocVien();
            frmHV.ShowDialog();
        }

        private void btnDanhSachHocVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ucHocVien ucHV = new ucHocVien();
            ucHV.Dock = DockStyle.Fill;

            XtraTabPage page = new XtraTabPage();
            page.Name = ucHV.Name;

            page.Text = btnDanhSachHocVien.Caption;
            page.Controls.Add(ucHV);
            xtraTabCtrlParent.TabPages.Add(page);
            xtraTabCtrlParent.SelectedTabPageIndex = xtraTabCtrlParent.TabPages.IndexOf(page) + 1;
        }

        private void btnKhoaHoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmKhoaHoc frmKH = new frmKhoaHoc();
            frmKH.ShowDialog();
        }

        private void btnPhongHoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmPhongHoc frmPH = new frmPhongHoc();
            frmPH.ShowDialog();
        }

        private void btnNgayHoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmNgayHoc frmNH = new frmNgayHoc();
            frmNH.ShowDialog();
        }

        private void btnCaHoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmCaHoc frmCH = new frmCaHoc();
            frmCH.ShowDialog();
        }

        private void btnChuongTrinhHoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmChuongTrinhHoc frmCTH = new frmChuongTrinhHoc();
            frmCTH.ShowDialog();
        }


        private void btnLoaiChuongTrinh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmLoaiChuongTrinh frmLCT = new frmLoaiChuongTrinh();
            frmLCT.ShowDialog();
        }

        private void btnTrinhDo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmTrinhDo frmTD = new frmTrinhDo();
            frmTD.ShowDialog();
        }

        private void btnLoaiDeThi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmLoaiDeThi frmLDT = new frmLoaiDeThi();
            frmLDT.ShowDialog();
        }

        private void btnDeThi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmDeThi frmDT = new frmDeThi();
            frmDT.ShowDialog();
        }

        private void btnThiXepLop_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ucDanhSachPhongThiXepLop ucDSPTXL = new ucDanhSachPhongThiXepLop();
            ucDSPTXL.Dock = DockStyle.Fill;

            XtraTabPage page = new XtraTabPage();
            page.Name = ucDSPTXL.Name;

            page.Text = "Danh Sách Phòng Thi Xếp Lớp";
            page.Controls.Add(ucDSPTXL);
            xtraTabCtrlParent.TabPages.Add(page);
            xtraTabCtrlParent.SelectedTabPageIndex = xtraTabCtrlParent.TabPages.IndexOf(page) + 1;
        }

        private void btnTimKiemHV_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmTimKiemHocVien frmTKHV = new frmTimKiemHocVien();
            frmTKHV.ShowDialog();
        }

        private void btnThemGiangVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmGiaoVien frmGV = new frmGiaoVien();
            frmGV.ShowDialog();
        }

        private void btnDanhSachGiangVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ucGiaoVien ucGV = new ucGiaoVien();
            ucGV.Dock = DockStyle.Fill;

            XtraTabPage page = new XtraTabPage();
            page.Name = ucGV.Name;

            page.Text = btnDanhSachGiaoVien.Caption;
            page.Controls.Add(ucGV);
            xtraTabCtrlParent.TabPages.Add(page);
            xtraTabCtrlParent.SelectedTabPageIndex = xtraTabCtrlParent.TabPages.IndexOf(page) + 1;
        }

        private void btnKetQuaThiXepLop_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnThiCuoiKhoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ucDanhSachPhongThiCuoiKhoa ucDSTCK = new ucDanhSachPhongThiCuoiKhoa();
            ucDSTCK.Dock = DockStyle.Fill;

            XtraTabPage page = new XtraTabPage();
            page.Name = ucDSTCK.Name;

            page.Text = "Danh Sách Phòng Thi Cuối Khóa";
            page.Controls.Add(ucDSTCK);
            xtraTabCtrlParent.TabPages.Add(page);
            xtraTabCtrlParent.SelectedTabPageIndex = xtraTabCtrlParent.TabPages.IndexOf(page) + 1;
        }

        private void btnLapPhieuThu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmPhieuThuTien frmPTT = new frmPhieuThuTien();
            frmPTT.ShowDialog();
        }

        private void btnLoaiLopHoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmLoaiLopHoc frmLLH = new frmLoaiLopHoc();
            frmLLH.ShowDialog();
        }

        private void btnDanhSachLopHoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ucLopHoc ucLH = new ucLopHoc();
            ucLH.Dock = DockStyle.Fill;

            XtraTabPage page = new XtraTabPage();
            page.Name = ucLH.Name;

            page.Text = btnDanhSachLopHoc.Caption;
            page.Controls.Add(ucLH);
            xtraTabCtrlParent.TabPages.Add(page);
            xtraTabCtrlParent.SelectedTabPageIndex = xtraTabCtrlParent.TabPages.IndexOf(page) + 1;
        }

        private void btnKetChuyen_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ucKetChuyenHocVien ucKCHV = new ucKetChuyenHocVien();
            ucKCHV.Dock = DockStyle.Fill;

            XtraTabPage page = new XtraTabPage();
            page.Name = ucKCHV.Name;

            page.Text = btnKetChuyen.Caption;
            page.Controls.Add(ucKCHV);
            xtraTabCtrlParent.TabPages.Add(page);
            xtraTabCtrlParent.SelectedTabPageIndex = xtraTabCtrlParent.TabPages.IndexOf(page) + 1;
        }

        #endregion

        #region BÁO CÁO

        private void btnBaoCaoGhiDanh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmBaoCaoGhiDanh frmBCGD = new frmBaoCaoGhiDanh();
            frmBCGD.ShowDialog();
        }

        private void btnBaoCaoHocVu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmBaoCaoHocVu frmBCHV = new frmBaoCaoHocVu();
            frmBCHV.ShowDialog();
        }

        private void btnBaoCaoKeToan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmBaoCaoKeToan frmBCKT = new frmBaoCaoKeToan();
            frmBCKT.ShowDialog();
        }

        #endregion

        private void xtraTabCtrlParent_CloseButtonClick(object sender, EventArgs e)
        {
            int index = xtraTabCtrlParent.SelectedTabPageIndex;
            xtraTabCtrlParent.TabPages.Remove(xtraTabCtrlParent.SelectedTabPage);
            xtraTabCtrlParent.SelectedTabPageIndex = index--;
        }
    }
}
